package com.skt.common_hr.yearadjustment.model
{
	
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.yearadjustment.YearAdjustmentFacade;
	import com.skt.common_hr.yearadjustment.model.vo.ComboFamilyVO;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class CreditInhabiComboProxy extends CommonProxy
	{
		public static const NAME:String = "CreditInhabiComboProxy";
		public var msgStr:String;
		public var comboInhabitants:ArrayCollection = new ArrayCollection();
		

		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function CreditInhabiComboProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function comboload(parnr:String, year:String):void
		{
			var param:Object = new Object();
			param["I_YEAR"] = year;
			param["I_PERNR"] = parnr;
			param["I_PGBN"] = "1";		//1조회 2저장
			loadData("Z_HR_0084_NEW", param, familyResult, familyFault); 
		}
		

		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function familyResult(event:ResultEvent):void
		{
			if(retCode==0) {
				trace("CreditInhabiComboProxy ---> familyResult()");
				comboInhabitants = parseCombo(event.result.ITAB);
				facade.sendNotification(YearAdjustmentFacade.LOAD_COMBO_CREDITINHAB_COMPLETE, this);
			}
			else {
				trace( "failed to load inhabitantsCombo: (" +event.result["RETCODE"] + ") "+event.result["RETTEXT"]);
				msgStr = event.result["RETTEXT"];
				facade.sendNotification(YearAdjustmentFacade.LOAD_COMBO_DONAINHAB_FAILED, this);
			}
		}
		
		//부양가족조회 실패
		private function familyFault(event:FaultEvent):void
		{
			trace("Fault message in inhabitantsCombo: " + event.fault.faultString);
			msgStr = event.fault.faultString;
			facade.sendNotification(YearAdjustmentFacade.LOAD_COMBO_DONAINHAB_FAILED, this);
		}
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 연말정산  MainList Value Object
		 */
		/**
		 * 개인정보
		 * 
		 * @param
		 * @return 가족 주민등록번호 Value Object
		 */
		private function parseCombo(arr:ArrayCollection):ArrayCollection
		{
			var returnArr:ArrayCollection = new ArrayCollection();
			for each(var reg:Object in arr){
				var vo:ComboFamilyVO = new ComboFamilyVO();
				
				vo.CODE	= reg["REGNO"];
				vo.TEXT	= reg["LNMHG"] + reg["FNMHG"] + "(" + reg["REGNO"].substr(0,6) + "-" + reg["REGNO"].substr(6,7)+ ")";
				vo.ENAME= reg["LNMHG"] + reg["FNMHG"];
//shgoo 2010.01.11
				vo.DPTID= reg["DPTID"];
				vo.DPTYP= reg["DPTYP"];
				
				//[dev5]
				vo.KDSVH= reg["KDSVH"];
				//[/dev5]
///////////////////
				
				returnArr.addItem(vo);
			}
			//returnArr.addItemAt({CODE:'',TEXT:'주민등록번호 선택'}, 0);
			return returnArr;
		}
		
	}
}